package cn.easier.activity.console.repository;



import cn.easier.activity.web.entity.ActivityTemplateInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * 模板信息 Repository
 */
@Repository
public interface ActivityTemplateInfoRepository extends JpaRepository<ActivityTemplateInfo, Integer>, JpaSpecificationExecutor<ActivityTemplateInfo> {

    @Query(value = "SELECT * FROM `activity_template_info` ORDER BY create_date DESC LIMIT ?", nativeQuery = true)
    List<ActivityTemplateInfo> getNewestByTop(Integer top);

    @Query(value = "SELECT VALUE FROM `activity_label` WHERE id = (SELECT template_type_id FROM `activity_template_info` WHERE id = ?)", nativeQuery = true)
    String getActivityType(Integer templateId);

    @Query(value = "UPDATE `activity_template_info` SET delete_flag = 2 WHERE id = ?", nativeQuery = true)
    @Modifying
    int deleteFlag(Integer id);
}
